Online PHP Function(s){ #Test PHP functions online!; }

  •  
 

 
Added: 08/02/2012 by John

How to - Install Memcached

Memcached is great, it caches your data in memory and operates with almost no overhead at all. Retriving data is almost instantly.

In this "how to" I explain how to install Memcached, configure Memcached and monitor Memcached. Look here to install memcache for php.

Installation (all unix, from source)

wget http://memcached.org/latest
tar -zxf memcached-*
cd memcached-*
./configure
make && make test
sudo make install
To start memcached an init file is useful. Memcached can be started automaticly this way.
For this we create a file named memcached in folder /etc/init.d
nano /etc/init.d/memcached


add the following lines to /etc/init.d/memcached
#!/bin/sh
        #
        # memcached    Startup script for memcached processes
        #
        # chkconfig: - 90 10
        # description: Memcache provides fast memory based storage.
        # processname: memcached

        [ -f memcached ] || exit 0

        prog="memcached"

        start() {
            echo -n $"Starting $prog "
            # Starting memcached with 64MB memory on port 11211 as deamon and user nobody
            memcached -m 64 -p 11211 -d -u nobody

            RETVAL=$?
            echo
            return $RETVAL
        }

        stop() {
            if test "x`pidof memcached`" != x; then
                echo -n $"Stopping $prog "
                killall memcached
                echo
            fi
            RETVAL=$?
            return $RETVAL
        }

        case "$1" in
                start)
                    start
                    ;;

                stop)
                    stop
                    ;;

                restart)
                    stop
                    start
                    ;;
                condrestart)
                    if test "x`pidof memcached`" != x; then
                        stop
                        start
                    fi
                    ;;

                *)
                    echo $"Usage: $0 {start|stop|restart|condrestart}"
                    exit 1

        esac

        exit $RETVAL
                    


Then we add run permissions, set it to auto start on reboot and start the service
chmod 755 /etc/init.d/memcached
chkconfig memcached on
/etc/init.d/memcached start


Installation (Debian, Ubuntu)

sudo apt-get install memcached


Installation (Redhat, Centos, Fedora)

yum install memcached


Configure Memcached

If you installed memcached through your package manager, you can edit the memcached settings this way, otherwise you can edit the settings in /etc/init.d/memcached
vi /etc/memcached.conf #debian
vi /etc/sysconfig/memcached #redhat


Memcached statistics

You can get Memcached statistics with the the following command:
watch "echo stats | nc 127.0.0.1 11211"

Or in the style of this website with PHP:
watch 'php -r '"'"'$m=new Memcache;$m->connect("127.0.0.1", 11211);print_r($m->getstats());'"'"


 

 

 


Comments

 
 
      © 2019 OnlinePHPFunctions.com | Disclaimer |       PHP versions: 7.2.4, 7.1.0, 7.0.14, 7.0.5, 7.0.4, 7.0.3, 7.0.2, 7.0.1, 5.6.29, 5.6.20, 5.6.19, 5.6.18, 5.6.17, 5.6.2, 5.5.34, 5.5.33, 5.5.32, 5.5.31, 5.5.18, 5.5.5, 5.5.0.a6, 5.5.0.a.5, 5.5.0.a.2, 5.4.34, 5.4.21, 5.4.13, 5.4.12, 5.4.11, 5.4.10, 5.4.9, 5.4.8, 5.4.7, 5.4.6, 5.4.5, 5.4.4, 5.4.3, 5.4.2, 5.4.1, 5.4.0, 5.3.29, 5.3.27, 5.3.23, 5.3.22, 5.3.21, 5.3.20, 5.3.19, 5.3.18, 5.3.17, 5.3.16, 5.3.15, 5.3.14, 5.3.13, 5.3.12, 5.3.11, 5.3.10, 5.3.2, 5.3.1, 5.3.0, 5.2.17, 5.2.16, 5.1.6, 5.1.5, 5.0.5, 5.0.4, 4.4.9